// 购物车模块
export default {
	namespaced:true,
	state(){
		return {
			cartList:[],  // 购物车列表信息
			cartTotal:{} // 购物车的统计信息
		}
	},
	getters:{
		// 建立快捷访问
		goodsCount:state=>state.cartTotal.goodsCount,
		checkedGoodsAmount:state=>state.cartTotal.checkedGoodsAmount,
		checkedGoodsCount:state=>state.cartTotal.checkedGoodsCount,
		goodsAmount:state=>state.cartTotal.goodsAmount,
	},
	mutations:{
		// 设置购物车数据
		setCartData(state,data){
			state.cartList = data.cartList
			state.cartTotal = data.cartTotal
		}
	},
	actions:{
		// 获取购物车数据
		async getInitData(context){
			let res = await uni.$http.get('/cart/index')
			context.commit('setCartData',res)
		}
	}
}